package cn.dlc.com.order.config;

import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 邓立川
 * @date 2020/12/31 15:31
 * @desc 流控模式为链路的时候配置的类
 */
@Configuration
public class FilterContextConfig {

    @Bean
    public FilterRegistrationBean sentinelFilterRegistration(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        // 绑定自己的CommonFilter
        filterRegistrationBean.setFilter(new CommonFilter());
        // 拦截路径
        filterRegistrationBean.addUrlPatterns("/*");
        // 参数设置为false
        filterRegistrationBean.addInitParameter(CommonFilter.WEB_CONTEXT_UNIFY, "false");
        // 自定义一个名称
        filterRegistrationBean.setName("sentinelFilter");
        filterRegistrationBean.setOrder(1);
        return filterRegistrationBean;
    }
}